package ClassExercise;

import java.util.Scanner;

//验证密码 3次机会
public class Exercise4 {
    public static void main(String[] args) {
        Scanner sr = new Scanner(System.in);
        int count=0;
        final int NUM=3;
        for(;;){

            if(count==0){
                System.out.print("您有"+NUM+"次机会输入密码:");
            }else{
                System.out.print("您还有"+(NUM-count)+"次机会输入密码:");
            }
            String psw = sr.next();
            if(psw.equals("123456")){
                System.out.println("登录成功!!");
                break;
            }else{
                count++;
                System.out.println("密码错误,登录失败!!请重新输入");
            }
            if(count==3){
                System.out.println("您输入密码错误且已经超过"+NUM+"次"+"很抱歉，登录失败，程序关闭");
                break;
            }
        }
    }
}
